﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SuperMarketSystem
{
    public partial class TSMGet : Form
    {
        TSM tsm;//新建一个记录存储类
        public TSMGet(ref TSM tsm)
        {
            InitializeComponent();
            this.tsm = tsm;//获取传入的记录类的引用
        }

        private void btnConfirm_Click(object sender, EventArgs e)//点击确认按钮
        {
           if(MyOtherUtils.checkDouble(textItemPrice.Text) && MyOtherUtils.checkInt(textItemNum.Text)
                && MyOtherUtils.checkInt(textItemID.Text) && MyOtherUtils.checkInt(textID.Text)&&MyOtherUtils.checkInt(textRoot.Text))//检查几个文本框内容和是否对应数据类型
            {
                tsm.ID = Convert.ToInt32(textID.Text);
                tsm.itemID = Convert.ToInt32(textItemID.Text);
                tsm.num = Convert.ToInt32(textItemNum.Text);
                tsm.price = Convert.ToDouble(textItemPrice.Text);
                tsm.root = Convert.ToInt32(textRoot.Text);
                tsm.sum = Convert.ToDouble(textItemSum.Text);
                this.Close();
            }
        }

        private void textItemPrice_TextChanged(object sender, EventArgs e)
        {
            if(MyOtherUtils.checkDouble(textItemPrice.Text) && MyOtherUtils.checkInt(textItemNum.Text))//检查价格和数量 类型正确则更新总价
            {
                textItemSum.Text = Convert.ToString(Convert.ToDouble(textItemPrice.Text) * Convert.ToInt32(textItemNum.Text));
            }
        }

        private void textItemNum_TextChanged(object sender, EventArgs e)
        {
            if (MyOtherUtils.checkDouble(textItemPrice.Text) && MyOtherUtils.checkInt(textItemNum.Text))//检查价格和数量 类型正确则更新总价
            {
                textItemSum.Text = Convert.ToString(Convert.ToDouble(textItemPrice.Text) * Convert.ToInt32(textItemNum.Text));
            }
        }
    }
}
